package com.rxy;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

        /*
                游戏面板 == 画布
         */

public class GamePanel extends JPanel {

    //BufferedImage java 当中的图片对象
    BufferedImage background;
    BufferedImage   cloud;
    BufferedImage trex;
    BufferedImage s1;
    BufferedImage fly1;

    public GamePanel(){
        try {
            background = ImageIO.read(new File("images/normal/bg1.png"));
            cloud = ImageIO.read(new File("images/normal/cloud.png"));
            trex = ImageIO.read(new File("images/normal/trex0.png"));
            s1 = ImageIO.read(new File("images/normal/cactus_big_1.png"));
            fly1 = ImageIO.read(new File("images/normal/pterosaur1.png"));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    //alt+ins 重写 Graphics g 画笔
    @Override
    public void print(Graphics g) {
        super.print(g);
        g.drawImage(background,0,120,background.getWidth(),background.getHeight(),null);
        g.drawImage(cloud,0,0,cloud.getWidth(),cloud.getHeight(),null);
        g.drawImage(trex,50,90,trex.getWidth(),trex.getHeight(),null);
        g.drawImage(s1,150,100,s1.getWidth(),s1.getHeight(),null);
        g.drawImage(fly1,500,50,fly1.getWidth(),fly1.getHeight(),null);

    }
}